package com.example.footballsystem.controller;

import com.example.footballsystem.entity.SeriesGame;
import com.example.footballsystem.entity.User;
import com.example.footballsystem.service.SeriesGameService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/SeriesGame")
@CrossOrigin(origins = "*")
public class SeriesGameController {
    @Autowired
    SeriesGameService seriesGameService;
    @PostMapping("/getAllSeriesGame")
    public ResponseEntity<List<SeriesGame>> getAllSeriesGame(){
        log.info(seriesGameService.getAllSeriesGame().toString());
        return ResponseEntity.ok().body(seriesGameService.getAllSeriesGame());
    }
    @PostMapping("/addSeriesGame")
    public ResponseEntity<Boolean> addSeriesGame(@RequestBody SeriesGame seriesGame){
        log.info("1231334567 "+seriesGame.toString());
        return ResponseEntity.ok().body(seriesGameService.addSeriesGame(seriesGame));
    }
    @GetMapping("/getUserInGame")
    public ResponseEntity<List<User>> getUserInGame(int seriesID){

        return ResponseEntity.ok().body(seriesGameService.getUserInGame(seriesID));
    }
    @GetMapping("/getHost")
    public ResponseEntity<User> getHost(int seriesID){
        log.info(seriesGameService.getHost(seriesID).toString());
        return ResponseEntity.ok().body(seriesGameService.getHost(seriesID));
    }
    @GetMapping("/getJoinGame")
    public ResponseEntity<List<SeriesGame>> getMineJoinGame(String account){
        log.info("join");
        return ResponseEntity.ok().body(seriesGameService.getJoinGame(account));
    }
    @GetMapping("/getMasterGame")
    public ResponseEntity<List<SeriesGame>> getMinMasterGame(String account){
        log.info("master");
        return ResponseEntity.ok().body(seriesGameService.getMasterGame(account));
    }
    @GetMapping("/joinGame")
    public ResponseEntity<Boolean> joinGame(int seriesID,String account){
        if(account==null){
            return ResponseEntity.ok().body(false);
        }else{
            log.info("joingame "+account);
            return ResponseEntity.ok().body(seriesGameService.joinGame(seriesID,account));
        }
    }
    @GetMapping("/getGameCount")
    public ResponseEntity<List<Integer>> getGameCount(){
        return ResponseEntity.ok().body(seriesGameService.getSeriesCount());
    }
    @GetMapping("count")
    public ResponseEntity<Integer> getCount(){
        return ResponseEntity.ok().body(seriesGameService.count());
    }
}
